package com.dong.c03_channel;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * <h1></h1>
 *
 * @author : dzj
 * @create: 2020-03-17 22:44
 */
public class P1_NioFileChannel01 {
    public static void main(String[] args) throws IOException {
        String str= "hello, 尚硅谷";
        FileOutputStream fos = new FileOutputStream("d:\\file01.txt");
        //包装为channel
        FileChannel fileChannel = fos.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        byte[] bytes = str.getBytes();
        buffer.put(bytes);
        //翻转
        buffer.flip();
        fileChannel.write(buffer);
        fileChannel.close();
        fos.close();
    }
}
